package com.example.cato_email.email;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.handler.GenericHandler;
import org.springframework.messaging.MessageHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;


@Component
public class OrderSubmitMessagehandler implements GenericHandler<Order> {


    private RestTemplate rest;

    private ApiProperties apiProps;

    public OrderSubmitMessagehandler() {
    }

    public OrderSubmitMessagehandler(RestTemplate rest, ApiProperties apiProps) {
        this.rest = rest;
        this.apiProps = apiProps;
    }

    @Override
    public Object handle(Order order, MessageHeaders messageHeaders) {
        rest.postForObject(apiProps.getUrl(),order,String.class);
        return null; //选择这个GenericHandle作为终点就要返回null，否则会报错，没有指定输出通道
    }
}
